package com.ex.controller;

import com.ex.componet.UserComponent;
import com.ex.dto.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;


@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    UserComponent userComponent;
    @Autowired
    RedisTemplate<String, Serializable> redisTemplate ;

    @RequestMapping("/health")
    private Integer test1(){
        return 200;
    }

    @RequestMapping("/getPerson")
    private Response health() {
        return new Response("张三", 20);
    }

    @RequestMapping("/foo")
    public String handleFoo() {
        return userComponent.get();
    }

    @RequestMapping(value="/foo2",method= RequestMethod.DELETE)
    public String handleFoo2() {
        return "Hello world";
    }


    @RequestMapping(value="/foo3",method= RequestMethod.GET)
    public String handleFoo3() {
        ValueOperations<String, Serializable> ops = null;
        ops = redisTemplate.opsForValue();
        ops.set("1","2");

        return  ops.get("1").toString();
    }
}

